package ${package.ModuleName!""}.controller;
import ${package.ModuleName!""}.result.R;
import ${package.ModuleName!""}.service.I${entity}Service;
import ${package.ModuleName!""}.model.dto.${entity}DTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.ModuleName!""}.model.entity.${entity};

/**
* ${table.comment!}控制层
* @author ${author}
* @date ${date}
*/
@Api(tags =" ${table.comment!}接口信息 ")
@AllArgsConstructor
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("${controllerMappingHyphen}")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${entity}ApiResource extends ${superControllerClass} {
    <#else>
public class ${entity}Controller {
    </#if>

    private I${entity}Service ${entity?replace("Sys","")?uncap_first}Service;

    /**
    * 查询所有
    * @params
    * @return
    */
    @GetMapping("/list")
    @ApiOperation(value = "查询所有",notes = "查询所有")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:list")
    public R list() {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.list());
    }

    /**
    * 分页查询
    * @params dto
    * @return
    */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询",notes = "分页查询")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:page")
    public R page(@RequestBody  ${entity}DTO dto) {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.page(dto.page()));
    }

    /**
    * 通过id查询
    * @params id
    * @return
    */
    @GetMapping("/get")
    @ApiOperation(value = "通过id查询",notes = "通过id查询")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:get")
    public R get(String id) {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.getById(id));
    }

    /**
    * 添加
    * @params entity
    * @return
    */
    @ApiOperation(value = "添加",notes = "添加")
    @PostMapping("/save")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:save")
    public R save(@RequestBody  ${entity} entity) {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.save(entity));
    }

    /**
    * 更新
    * @params entity
    * @return
    */
    @PostMapping("/update")
    @ApiOperation(value = "更新",notes = "更新")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:update")
    public R update(@RequestBody  ${entity} entity) {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.updateById(entity));
    }

    /**
    * 通过id删除
    * @params id
    * @return
    */
    @PostMapping("/delete")
    @ApiOperation(value = "通过id删除",notes = "通过id删除")
    <#if cfg.hasPermission == false>// </#if>@RequiresPermissions("${controllerMappingHyphen}:delete")
    public R delete(String id) {
    return R.ok(this.${entity?replace("Sys","")?uncap_first}Service.removeById(id));
    }

    }
</#if>
